using System;
using System.Data;
using NHibernate;
using NHibernate.Cfg;

namespace Serpis
{
	public class AppDbConnection
	{
		//Singleton
		private static AppDbConnection instance = new AppDbConnection();

		private AppDbConnection()
		{
		}
		
		public static AppDbConnection Instance {
			get {return instance;}
		}

		private IDbConnection dbConnection=null;				
		public IDbConnection DbConnection {
			get {
				if (dbConnection == null) {
				}
				return dbConnection;
			}
		}
		
		private ISessionFactory sessionFactory;
		public ISessionFactory SessionFactory{
			get{
				if (sessionFactory==null) {
					Configuration configuration = new Configuration();
					configuration.Configure();
					configuration.AddAssembly("PVenta");
					sessionFactory = configuration.BuildSessionFactory();
				}return sessionFactory;
			}
		}
		
		public void Close()
		{
			dbConnection.Close();
		}
	}
}
